"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var vector_1 = __importDefault(require("../../tools/vector"));
var Neuron = (function () {
    function Neuron(shape, weights) {
        this.weights = [];
        this.bias = 0;
        if (weights && weights.length !== 0) {
            this.weights = weights.slice(0, -1);
            this.bias = weights.slice(-1)[0];
        }
        else {
            for (var i = 0; i < shape; i++) {
                this.weights.push(Math.random());
            }
        }
    }
    Neuron.prototype.feedforward = function (inputs) {
        if (inputs.length === this.weights.length) {
            return vector_1.default.dot(this.weights, inputs) + this.bias;
        }
        else {
            throw TypeError("inputs shape was not matched");
        }
    };
    Neuron.prototype.backward = function (inputs, derivative) {
        var lastWeights = this.weights.slice(0);
        for (var i = 0; i < this.weights.length; i++) {
            this.weights[i] -= derivative * inputs[i];
        }
        this.bias -= derivative;
        return lastWeights;
    };
    Neuron.prototype.snapshot = function () {
        return { weigths: this.weights, bias: this.bias };
    };
    return Neuron;
}());
exports.default = Neuron;
module.exports = Neuron;
